<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>药典管理-药品查询</title>
		<link type="text/css" rel="stylesheet"
			href="${pageContext.request.contextPath}/drugUI/css/style.css" />
		<link type="text/css" rel="stylesheet"
			href="${pageContext.request.contextPath}/drugUI/css/main.css" />
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/drugUI/js/util.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/drugUI/js/jquery1.4.2.min.js"></script>
	</head>
	<body>
		<div id="container">
			<form name="Form1" method="post" id="Form1">
				<!--查询栏 开始-->
				<div class="current">
					<div class="current_con">
						<div class="help">
							<a href="#"><img
									src="${pageContext.request.contextPath}/drugUI/image/help.gif"
									title="帮助"
									onclick="showLayer('C5','${pageContext.request.contextPath}')" />
							</a>
						</div>
						<span>_当前位置：</span> 药典管理 >>药品查询
					</div>
				</div>
				<input id="criteriaCount" type="hidden" value="2" />
				<table class="table02" id="tbCriteria" align="center">
					<tr class="tr_title">
						<td width="48" align="right">
							逻辑
						</td>
						<td width="144" height="20">
							检索项
						</td>
						<td width="183">
							检索词
						</td>
						<td width="76">
							匹配度
						</td>
					</tr>
					<tr class='tr_1'>
						<td width="67" align="right">
							<div>
								<img
									src="${pageContext.request.contextPath}/drugUI/image/iw_plus.gif"
									onClick="addCriteria(0);">
								<img
									src="${pageContext.request.contextPath}/drugUI/image/iw_minus.gif"
									onClick="addCriteria(1);">
							</div>
						</td>
						<td width="120">
							<select name="searchfield1" id="searchfield1">
								<option value="drugname">
									药品名称
								</option>
								<option value="code">
									药品国际编码
								</option>
								<option value="buliangfanying">
									不良反应
								</option>
								<option value="zhuyishixiang">
									注意事项
								</option>
								<option value="yongfayongliang">
									用法用量
								</option>
							</select>
						</td>
						<td width="239" height="35">
							<input name="text1" id="text1" size="30">
						</td>
						<td width="55">
							<select name="equalorlike1" id="equalorlike1" size="1">
								<option value="like" selected>
									模糊
								</option>
								<option value="=">
									精确
								</option>
							</select>
						</td>
					</tr>
					<tr class='tr_2'>
						<td width="67" align="right">
							<select name="andor2" id="andor2" size="1">
								<option value="and" selected>
									并且
								</option>
								<option value="or">
									或者
								</option>
							</select>
						</td>
						<td width="120">
							<select name="searchfield2" id="searchfield2">
								<option value="drugname">
									药品名称
								</option>
								<option value="code" selected>
									药品国际编码
								</option>
								<option value="buliangfanying">
									不良反应
								</option>
								<option value="zhuyishixiang">
									注意事项
								</option>
								<option value="yongfayongliang">
									用法用量
								</option>
							</select>
						</td>
						<td width="239" height="35">
							<input name="text2" id="text2" size="30">
						</td>
						<td width="55">
							<select name="equalorlike2" id="equalorlike2" size="1">
								<option value="like" selected>
									模糊
								</option>
								<option value="=">
									精确
								</option>
							</select>
						</td>
					</tr>
				</table>
				<table class="table02" align="center">
					<tr>
						<td class="td_bottom" align="center" colSpan="6">
							<input type="button" name="btnSearch" value="查 询"
								onClick="javascript:reflush('1');" id="btnSearch" class="btn02" />
							&nbsp;
							<input type="button" name="btnAdd" value="增加"
								onClick="javascript:showHandleDialog('add','');" id="btnAdd"
								class="btn02" />
							&nbsp;
							<input type="button" name="btnDelete" value="删除"
								onClick="javascript:del();" id="btnDelete" class="btn02" />
							&nbsp;
						</td>
					</tr>
				</table>
				<!--查询栏 结束-->

				<!--列表输出-->
				<div id="content">
					<div id="tabContainer">
						<!--列表输出表头-->
						<div id="tabTitle">
							<table width="100%" class="table01" align="center"
								cellspacing="0">
								<tr align="center" class="tr_title">
									<td width="5%" height="30" scope="col">
										<input id='cbSelectAll' name='cbSelectAll' type='checkbox'
											onclick="selectOrCancelBox( 'cbSelectAll', 'enplrpcds' );" />
									</td>
									<td width="15%" scope="col">
										药品名称
									</td>
									<td width="15%" scope="col">
										药品国际编码
									</td>
									<td width="15%" scope="col">
										注意事项
									</td>
									<td width="15%" scope="col">
										形状
									</td>
									<td width="15%" scope="col">
										不良反应
									</td>
									<td width="10%" scope="col">
										用法和用量
									</td>
									<td width="10%" scope="col">
										药品规格
									</td>
								</tr>
							</table>
						</div>
						<!--列表输出各行数据-->
						<div id="tabLines">
							<table width="100%" class="table01" align="center"
								cellspacing="0"
								style="TABLE-LAYOUT: fixed; word-break: break-all">
								<tbody id="__list">
									<c:forEach items="${drugList}" var="s" varStatus="i">
										<tr <c:if test="${i.index%2==0}"> class = 'tr_1'</c:if>
											<c:if test="${i.index%2==1}"> class = 'tr_2'</c:if>>
											<td width="5%" scope="col">
												<input name='enplrpcds' type='checkbox'
													value="${ s.drugid }" />
											</td>
											<td width="15%">
												<a href="#"
													onClick="javascript:showHandleDialog( 'edit','${s.drugid}' )">${s.drugname
													}</a>
											</td>
											<td width="15%">
												${s.code}
											</td>
											<td width="15%">
												${s.zhuyishixiang}
											</td>
											<td width="15%">
												${s.xingzhuang }
											</td>
											<td width="15%">
												${s.buliangfanying}
											</td>
											<td width="10%">
												${s.yongfayongliang }
											</td>
											<td width="10%">
												${s.specification }
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div id="footer">
					<table width="98%" border="0" cellpadding="0" cellspacing="0"
						align="center">
						<tr>
							<td>
								<label id="_paginationBar">
									${reportViewList.paginationBar }
								</label>
							</td>
						</tr>
					</table>
				</div>
			</form>
		</div>
		<script language="javascript">
		function addCriteria(flag){
		var i = document.getElementById("criteriaCount").value;//检索条件的个数
		var table1=document.getElementById("tbCriteria");
		var tRow= table1.rows;
		if(flag==0){
		i = i-0;
		if(i>=5)
		{
		alert('对不起,至多只能添加应该剩'+document.getElementById('searchfield1').options.length+'个.');
		return false;
		}
		var newBlankRow = table1.insertRow(tRow.length);
		var point = newBlankRow.rowIndex;
		tRow[point].insertCell();
		tRow[point].cells(0).innerHTML = '<td width="67" align="right"><select name="andor'+i+'" id="andor'+i+'" size="1"><option value="and" selected>并且</option><option value="or">或者</option></select></td>';
		tRow[point].insertCell();
		var strTag='<td width="120"><select name="searchfield'+i+'" id="searchfield'+i+'">';
		var selectEl=document.getElementById('searchfield1');
		for (k=0;k<selectEl.options.length;k++){
		var selected=(tRow.length-1!=(k+1)?"":"selected");
		strTag += "<option value='" +selectEl.options[k].value + "' "+selected+">" + selectEl.options[k].text + "</option>";
		}
		strTag+='</select></td>';
		tRow[point].cells(1).innerHTML=strTag;
		tRow[point].insertCell();
		tRow[point].cells(2).innerHTML = '<td width="239" height="35"><input name="text'+i+'" id="text'+i+'"  size="30"></td>';          
		tRow[point].insertCell();
		tRow[point].cells(3).innerHTML = '<td width="55"><select name="equalorlike'+i+'" id="equalorlike'+i+'" size="1"><option value="like" selected>模糊</option><option value="=">精确</option></select></td>';
		tRow[point].className="tr_"+(tRow.length%2+1);
		document.getElementById("criteriaCount").value = i+1;
		}
		else
		{
		i = i-0;
		if(i<=1)
		{
		  alert("对不起,至少应该剩一个.");
		  return false;
		}
		else
		{
		table1.deleteRow(tRow.length-1);
		}
		document.getElementById("criteriaCount").value = i-1;
		}
		}
		function reflush( pageNum )
		{
		//logic:and,field:drugname,operation:like,value:llll
		var table1=document.getElementById("tbCriteria");
		var tRow= table1.rows;
		var rowLength=tRow.length;
		var searchContent='';
		for(i=1;i<rowLength;i++)
		{
		   tempField = 'searchField'+i;
           tempText = 'text'+i;
           tempLogic='andor'+i;
           tempOperation='equalorlike'+i;
		   if(i==1)
		   {
		   searchContent+='logic:and,field:'+document.getElementById(tempField).value+',operation:'+document.getElementById(tempOperation).value+',filedValue:'+window.encodeURI(document.getElementById(tempText).value)+'';
		   }
		   else
		   {
		   searchContent+=';logic:'+document.getElementById(tempLogic).value+',field:'+document.getElementById(tempField).value+',operation:'+document.getElementById(tempOperation).value+',filedValue:'+window.encodeURI(document.getElementById(tempText).value)+'';
		   }
		}
			$.ajax({
		        "url": "drug.query.action",
		        "data": 
		        { 
		        	"pageNum": pageNum,
		        	"searchContents":searchContent
		        },
		        "dataType": "json",
		        "type": "POST",
		        "success": function( obj )
		        { 	
					$("#__list").empty();
					if(obj!=null)
					{
					$.each(obj.statisticsList, function(index, s){
							var trObj = $("<tr></tr>");
							trObj.attr("align","center");  
		                    $("<td  width=\"5%\"></td>").html( "<input type=\"checkbox\" name=\"enplrpcds\" value='"+ s.drugid +"' />").appendTo(trObj);    
		                    $("<td  width=\"15%\"></td>").html("<a href=\"#\" onClick=\"javascript:showHandleDialog( 'edit','"+s.drugid+"' )\">"+s.drugname+"</a>" ).appendTo(trObj);
		                    $("<td  width=\"15%\"></td>").html(s.code).appendTo(trObj); 
		                    $("<td  width=\"15%\"></td>").html(s.zhuyishixiang ).appendTo(trObj);
		                    $("<td  width=\"15%\"></td>").html(s.xingzhuang).appendTo(trObj);
		                    $("<td  width=\"15%\"></td>").html(s.buliangfanying).appendTo(trObj);
		                    $("<td  width=\"10%\"></td>").html(s.yongfayongliang).appendTo(trObj);
		                    $("<td  width=\"10%\"></td>").html(s.specification).appendTo(trObj);
		                    trObj.appendTo($("#__list")); 
		                    $('tbody[id*=__list] > tr:even').addClass('tr_1');
		                    $('tbody[id*=__list] > tr:odd').addClass('tr_2');
		                    $('tbody[id*=__list] > tr[id!=totalRow]').mouseover(function(){$(this).removeClass();$(this).addClass('tr_0');})
		                    $('tbody[id*=__list] > tr[id!=totalRow]:even').mouseout(function(){$(this).addClass('tr_1');})
		                    $('tbody[id*=__list] > tr[id!=totalRow]:odd').mouseout(function(){$(this).addClass('tr_2');})
		            });
		            $("#_paginationBar").html(obj.paginationBar);
					}
		        }
		    });
		}
		function showHandleDialog(action,planId){
			var url;
			if ( action == "add" )
				url = "drug.edit.action?type=add";
			else
				url = "drug.edit.action?type=edit&drugid="+planId;
			var returnValue = modelWindow(url,1040,300);
			if (returnValue == "ok")
				reflush('1');
		}
		function del()
		{
		var pprcd = getCheckBoxValues("fsbstrpcds");
			if ( pprcd == "")
			{
				alert( "请选择需要删除的记录!" );
				return false;
			}
			if( !confirm( "您确定要删除选定的记录吗？" ) )
				return;
			$.ajax({
			    'url': 'drug.deleteDrugs.action',
			    'data': {'fsbstrpcds':pprcd},
			    'dataType': 'text',
			    'type': 'POST',
			    'success': function( flag )
			    {
			    	if ( flag == '0' )
			    	{
			    		reflush( document.getElementById("pageNum" ).value );
			    		alert("删除成功！");	
			    	}
			    	else
			    	{
			    	     alert("删除失败，请重新阐述或者联系管理员！");
			    	}
				}
		   });
		}
		window.onload = function(){resizeTabBody( 'tabLines' )};
		window.onresize = function(){resizeTabBody( 'tabLines' )};
	</script>
	</body>
</html>
<%@ include file="/drugUI/common/footer.jsp"%>
